Skip to content

[mypy] Fixes and annotates other/least_recently_used #5656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

spazm
Copy link
Contributor

@spazm spazm commented Oct 29, 2021

Describe your change:

  • fix bug in dq_removal code. Needed to pass key to .remove() rather than index.
  • remove incorrect annotation to make the __init__ an abstract function.
  • Annotate all functions and class Generic[T]
  • Expand example to show creating a LRUCache over concrete and mixed types.
  • Adds doctest to LRUCache class
  • Adds assert test in main.

Related to: #4052

Before

% git checkout master
Your branch is up to date with 'origin/master'.

% mypy --ignore-missing-imports --install-types least_recently_used.py
least_recently_used.py:57: error: Cannot instantiate abstract class "LRUCache" with abstract attribute "__init__"
Found 1 error in 1 file (checked 1 source file)
% mypy --strict least_recently_used.py
least_recently_used.py:27: error: Function is missing a type annotation
least_recently_used.py:33: error: Unsupported right operand type for in ("object")
least_recently_used.py:34: error: Argument 1 to "len" has incompatible type "object"; expected "Sized"
least_recently_used.py:35: error: "object" has no attribute "pop"
least_recently_used.py:36: error: "object" has no attribute "remove"
least_recently_used.py:39: error: Need type annotation for "key"
least_recently_used.py:39: error: Argument 1 to "enumerate" has incompatible type "object"; expected "Iterable[<nothing>]"
least_recently_used.py:43: error: "object" has no attribute "remove"
least_recently_used.py:45: error: "object" has no attribute "appendleft"
least_recently_used.py:46: error: "object" has no attribute "add"
least_recently_used.py:48: error: Function is missing a return type annotation
least_recently_used.py:48: note: Use "-> None" if function does not return a value
least_recently_used.py:52: error: "object" has no attribute "__iter__"; maybe "__str__" or "__dir__"? (not iterable)
least_recently_used.py:57: error: Cannot instantiate abstract class "LRUCache" with abstract attribute "__init__"
least_recently_used.py:58: error: Call to untyped function "refer" in typed context
least_recently_used.py:59: error: Call to untyped function "refer" in typed context
least_recently_used.py:60: error: Call to untyped function "refer" in typed context
least_recently_used.py:61: error: Call to untyped function "refer" in typed context
least_recently_used.py:62: error: Call to untyped function "refer" in typed context
least_recently_used.py:63: error: Call to untyped function "refer" in typed context
least_recently_used.py:64: error: Call to untyped function "display" in typed context
Found 20 errors in 1 file (checked 1 source file)

After

% git checkout mypy-fix-other-least_recently_used
Switched to branch 'mypy-fix-other-least_recently_used'
Your branch is up to date with 'origin/mypy-fix-other-least_recently_used'.

% mypy --strict least_recently_used.py
Success: no issues found in 1 source file
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Oct 29, 2021
@ghost
Copy link

ghost commented Oct 29, 2021

Multiple Pull Request Detected

@spazm, we are extremely excited that you want to submit multiple algorithms in this repository but we have a limit on how many pull request a user can keep open at a time. This is to make sure all maintainers and users focus on a limited number of pull requests at a time to maintain the quality of the code.

This pull request is being closed as the user already has an open pull request. Please focus on your previous pull request before opening another one. Thank you for your cooperation.

User opened pull requests (including this one): #5656, #5647, #5621, #5591

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant